package com.bean;

import java.util.Random;

public class Test {
    public static void quickSort(int a[], int low, int high) {
        int i = low, j = high;
        int pivot = low + (high - low) / 2;
        while (i <= j) {
            while (a[i] < a[pivot]) {
                i++;
            }
            while (a[j] > a[pivot]) {
                j--;
            }
            if (i <= j) {
                int temp = a[i];
                a[i] = a[j];
                a[j] = temp;
                i++;
                j--;
            }
            //计算左边序列的
            if (low < j) {
                quickSort(a, low, j);
            }
            //计算右边序列的
            if (i < high) {
                quickSort(a, i, high);
            }
        }

    }

    public static void main(String[] args) {
        int[] a = new int[100];
        Random random = new Random();
        for (int i = 0; i < a.length; i++) {
            a[i] = random.nextInt(1000);
        }
        quickSort(a, 0, a.length - 1);
        for (int i = 0; i < a.length; i++) {
            if (i % 10 == 0) {
                System.out.println(" ");
            }
            System.out.print(a[i] + " ");
        }
    }
}
